home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.2 / StartingAmigaC / exam2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  4.4 KB  |  164 lines

  1. /*
  2.    Example of opening a simple window on a custom screen - #2
  3.    written by Dan Schein April-88 for the 1988 AMIGA Developers Conference. 
  4.  
  5.    This example, and all those based on this example, were compiled and
  6.    tested with the Lattice V4.0 compiler.
  7. */
  8.  
  9. /*
  10.   Copyright (c) 1988 Commodore-Amiga, Inc.
  11.  
  12.   Executables based on this information may be used in software
  13.   for Commodore Amiga computers.  All other rights reserved.
  14.  
  15.   This information is provided "as is"; no warranties are made.
  16.   All use is at your own risk, and no liability or responsibility is assumed.
  17. */
  18.  
  19.  
  20. #include <exec/types.h>
  21. #include <intuition/intuition.h>
  22. #include <libraries/dos.h>
  23.  
  24. /*
  25.    Define the Version of the Amiga OS we want (require)
  26.  
  27.    Operating System Version Information
  28.  
  29.       0     Any version is OK
  30.       30    1.0 or higher
  31.       31    1.1 NTSC or Higher
  32.       32    1.1 PAL  or Higher
  33.       33    1.2 or higher
  34.       34    1.3 or higher
  35.  
  36. */
  37.  
  38. #define INTUITION_REV 0
  39. #define GRAPHICS_REV  0
  40.  
  41. struct TextAttr MyFont =
  42. {
  43.    "topaz.font",                             /* Font Name                 */
  44.    TOPAZ_EIGHTY,                             /* Font Height               */
  45.    FS_NORMAL,                                /* Style                     */
  46.    FPF_ROMFONT                               /* Preferences               */
  47. };
  48.  
  49. struct NewScreen OurScreen =
  50. {
  51.    0, 0,                                     /* LeftEdge and TopEdge     */
  52.    640, 200,                                 /* Width and Height         */
  53.    2,                                        /* Depth (4 colors)         */
  54.    0, 1,                                     /* DetailPen and BlockPen   */
  55.    HIRES,                                    /* Special Display Mode     */
  56.    CUSTOMSCREEN,                             /* The Screen Type          */
  57.    &MyFont,                                  /* Use our own Font         */
  58.    "A Simple Screen",                        /* Screen Title             */
  59.    NULL,                                     /* Special Screen Gadgets   */
  60.    NULL                                      /* Special CustomBitMap     */
  61. };
  62.  
  63. struct NewWindow OurWindow =
  64. {
  65.    20, 20,                                   /* LeftEdge and TopEdge      */
  66.    300, 100,                                 /* Width and Height          */
  67.    0, 1,                                     /* DetailPen and BlockPen    */
  68.    NULL,                                     /* IDCMP Flags               */
  69.    ACTIVATE|SMART_REFRESH,                   /* Flags                     */
  70.    NULL, NULL,                               /* Gadget and Image pointers */
  71.    "A Simple Window",                        /* Window Title              */
  72.    NULL,                                     /* Screen pointer            */
  73.    NULL,                                     /* BitMap pointer            */
  74.    0, 0,                                     /* MinWidth and MinHeight    */
  75.    0, 0,                                     /* MaxWidth and MaxHeight    */
  76.    CUSTOMSCREEN                              /* Type of window            */
  77. };
  78.  
  79. struct Screen *screen;
  80. struct Window *window;
  81. struct GfxBase *GfxBase;
  82. struct IntuitionBase *IntuitionBase;
  83.  
  84. void main(), cleanexit(), cleanup();
  85.  
  86.  
  87.  
  88. void main()
  89. {
  90.    LONG i;
  91.               /* Method #1 of opening and error testing */
  92.  
  93.    IntuitionBase=(struct IntuitionBase*)
  94.       OpenLibrary("intuition.library",INTUITION_REV);
  95.  
  96.    if (IntuitionBase == NULL)
  97.    {
  98.       cleanexit ("Open Intuition Library failed!\n", RETURN_FAIL);
  99.    }
  100.  
  101.    GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",GRAPHICS_REV);
  102.  
  103.    if (GfxBase == NULL)
  104.    {
  105.       cleanexit ("Open Graphics Library failed!\n", RETURN_FAIL);
  106.    }
  107.  
  108.               /* Method #2 of opening and error testing */
  109.  
  110.    if((screen=(struct Screen*)OpenScreen(&OurScreen))==NULL)
  111.    {
  112.       cleanexit ("Open Screen failed!\n", RETURN_FAIL);
  113.    }
  114.  
  115.    OurWindow.Screen=screen;
  116.  
  117.    if((window=(struct Window *)OpenWindow(&OurWindow))==NULL)
  118.    {
  119.       cleanexit ("Open Window failed!\n", RETURN_FAIL);
  120.    }
  121.  
  122.    Move(window->RPort, 20, 20);
  123.    Text(window->RPort, "Our own TEXT string!", 20);
  124.  
  125.    for(i=0; i<1000000; i++);
  126.  
  127.    cleanup();
  128.    exit (RETURN_OK);
  129. }
  130.  
  131.  
  132.  
  133. void cleanexit(s, err)
  134. UBYTE *s;
  135. int err;
  136. {
  137.    if(*s) printf(s);
  138.    cleanup();
  139.    exit(err);
  140. }
  141.  
  142. void cleanup()
  143. {
  144.    if(window)
  145.    {
  146.       CloseWindow(window);
  147.    }
  148.  
  149.    if(screen)
  150.    {
  151.       CloseScreen(screen);
  152.    }
  153.  
  154.    if(GfxBase)
  155.    {
  156.       CloseLibrary(GfxBase);
  157.    }
  158.  
  159.    if(IntuitionBase)
  160.    {
  161.       CloseLibrary(IntuitionBase);
  162.    }
  163. }
  164.